//图片识别

const http = require('http');
const fs = require('fs');
const request = require("request");
const AipOcrClient = require("baidu-aip-sdk").ocr;

 
	// 设置APPID/AK/SK
	const APP_ID = "19532942";
	const API_KEY = "OFCtPKWg3tjVykoKHIdAsTNC";
	const SECRET_KEY = "CAEZ2iXO0C3ndu7Zk1OS3XwoYukXbCUr";
 
	// 新建一个对象，建议只保存一个对象调用服务接口
	const client = new AipOcrClient(APP_ID, API_KEY, SECRET_KEY);
    const image = fs.readFileSync('./t01f78c8c43be47712f.jpg');
    

    // let m= request('https://qqwx.zhangguangzong.com/jpg/200/f-h-4.png').getInputStream()
//    let m= request.put('https://qqwx.zhangguangzong.com/jpg/200/f-h-4.png')
//     console.log(m)


// request
//   .get('http://imagse1.fcrenti.com/photo/picss/201928/201928212739625.jpg')
//   .on('response', function(response) {
//     console.log(response.statusCode) // 200
//     console.log(response.headers['content-type']) // 'image/png'
//   })
//   .pipe(request.put('http://imagse1.fcrenti.com/photo/picss/201928/201928212739625.jpg'))
//   let m =  request.put('http://imagse1.fcrenti.com/photo/picss/201928/201928212739625.jpg').pipe()

	
	const base64Img = new Buffer(image).toString('base64');
    client.generalBasic(base64Img).then(function (result) {
        //res.end(JSON.stringify(result));
        console.log(result);
    });




// let sm =  request.get('http://imagse1.fcrenti.com/photo/picss/201928/201928212739625.jpg').on('response', function(response) {
//     let [,de] = response.headers['content-type'].split('/');   
//     if(response.statusCode === 200) {
//         sm.pipe(fs.createWriteStream(`9999999999.${de}`))
//     }
//   })

 
//   console.log(m.uri)
